package jp.eisbahn.mgapi.api.updates;

import java.text.ParseException;
import java.util.Date;

import org.json.simple.JSONObject;

import jp.eisbahn.mgapi.api.Model;
import jp.eisbahn.mgapi.util.DateUtils;

/**
 * This model class represents an Activity Object.
 * @author Yoichiro Tanaka
 */
public class ActivityObject extends Model {

    /**
     * Initialize this instance.
     * @param newOriginal The JSON object.
     */
    public ActivityObject(final JSONObject newOriginal) {
        super(newOriginal);
    }

    /**
     * Retrieve a link.
     * @return The link string.
     */
    public final String getLink() {
        return getPropertyString("link");
    }

    /**
     * Retrieve a posted time.
     * @return The postedTime value as Date object.
     * @throws ParseException If the date string could not be parsed.
     */
    public final Date getPostedTime() throws ParseException {
        String postedTime = getPropertyString("postedTime");
        if (postedTime != null) {
            return DateUtils.convertDate(postedTime);
        } else {
            return null;
        }
    }

    /**
     * Retrieve an object type.
     * @return The object type.
     */
    public final String getObjectType() {
        return getPropertyString("objectType");
    }

    /**
     * Retrieve an additional information as a JSON object.
     * @param key The key string.
     * @return The JSON object related by the key.
     */
    public final JSONObject getExtendedInfoAsJson(final String key) {
        return getPropertyJSONObject(key);
    }

    /**
     * Retrieve an additional information as a string.
     * @param key The key string.
     * @return The string related by the key.
     */
    public final String getExtendedInfoAsString(final String key) {
        return getPropertyString(key);
    }

    /**
     * Retrieve an ID.
     * @return The ID string.
     */
    public final String getId() {
        return getPropertyString("id");
    }

}
